# 线程：执行单位，进程：资源单位
# 每一个进程至少要有一个线程

# 启动一个程序默认都会有一个主线程

# if __name__ == '__main__':
#     print("你好")

# # 多线程
# from threading import Thread  # 线程类
#
# def func():
#     for i in range(100):
#         print("func", i)
#
# if __name__ == '__main__':
#     t = Thread(target=func)
#     t.start() # 多线程状态设为可以开始工作状态，具体执行时间由CPU决定
#     for i in range(100):
#         print('main', i)

# from threading import Thread
#
# class MyThread(Thread):  #
#     def run(self):
#         for i in range(1000):
#             print("子线程", i)
#
# if __name__ == '__main__':
#     t = MyThread()
#     # t.run() # 错 方法调用->单线程
#     t.start() # 开始线程
#
#     for i in range(1000):
#         print("主线程", i)


# # 创建多进程
# from multiprocessing import Process
#
# def func():
#     for i in range(100):
#         print("son", i)
#
# if __name__ == '__main__':
#     p = Process(target=func)
#     p.start()
#
#     for i in range(100):
#         print("main", i)


# 多线程
from threading import Thread  # 线程类

def func(name): # 传参时
    for i in range(100):
        print(name, i)

if __name__ == '__main__':
    t1 = Thread(target=func, args=("周杰伦",)) # 传递参数必须是元组
    t1.start() # 多线程状态设为可以开始工作状态，具体执行时间由CPU决定
    t2 = Thread(target=func, args=("王力宏",))
    t2.start()
    # for i in range(100):
    #     print('main', i)
